home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / c / qtools0.2-src.lha / src / libqtools / memory.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-07-18  |  35.7 KB  |  701 lines

  1. #define    LIBQTOOLS_CORE
  2. #include "../include/libqtools.h"
  3.  
  4. /*#undef        oprintf */
  5. /*#define       oprintf printf */
  6.  
  7. /*
  8.  * =============
  9.  * PrintBSPFileSizes
  10.  * 
  11.  * Dumps info about current file
  12.  * =============
  13.  */
  14. void PrintClusters(__memBase, int printType, bool toDisk)
  15. {
  16.   if (bspMem) {
  17.     if (!bspMem->bspVersion)
  18.       bspMem->bspVersion = BSP_VERSION_Q1;
  19.     if (!printType)
  20.       printType = bspMem->availHeaders;
  21.  
  22.     oprintf("printmask: %lx\n", printType);
  23.  
  24.     mprintf("----- Statistics --------\n");
  25.     if (bspMem->availHeaders & printType & LUMP_PLANES)
  26.       mprintf("%5i planes       %6i\n", bspMem->shared.all.numplanes, (int)(bspMem->shared.all.numplanes * sizeof(struct dplane_t)));
  27.  
  28.     if (bspMem->availHeaders & printType & LUMP_VERTEXES)
  29.       mprintf("%5i vertexes     %6i\n", bspMem->shared.all.numvertexes, (int)(bspMem->shared.all.numvertexes * sizeof(struct dvertex_t)));
  30.  
  31.     if (bspMem->availHeaders & printType & LUMP_FACES)
  32.       mprintf("%5i faces        %6i\n", bspMem->shared.all.numfaces, (int)(bspMem->shared.all.numfaces * sizeof(struct dface_t)));
  33.  
  34.     if (bspMem->availHeaders & printType & LUMP_MARKSURFACES)
  35.       mprintf("%5i %s %6i\n", bspMem->shared.all.nummarksurfaces, (bspMem->bspVersion == BSP_VERSION_Q1 ? "marksurfaces" : "leaffaces   "), (int)(bspMem->shared.all.nummarksurfaces * sizeof(unsigned short int)));
  36.  
  37.     if (bspMem->availHeaders & printType & LUMP_SURFEDGES)
  38.       mprintf("%5i surfedges    %6i\n", bspMem->shared.all.numsurfedges, (int)(bspMem->shared.all.numsurfedges * sizeof(int)));
  39.  
  40.     if (bspMem->availHeaders & printType & LUMP_EDGES)
  41.       mprintf("%5i edges        %6i\n", bspMem->shared.all.numedges, (int)(bspMem->shared.all.numedges * sizeof(struct dedge_t)));
  42.  
  43.     if (bspMem->availHeaders & printType & LUMP_LIGHTING)
  44.       mprintf("      lightdata    %6i\n", bspMem->shared.all.lightdatasize);
  45.     if (bspMem->availHeaders & printType & LUMP_VISIBILITY)
  46.       mprintf("      visdata      %6i\n", bspMem->shared.all.visdatasize);
  47.     if (bspMem->availHeaders & printType & LUMP_ENTITIES)
  48.       mprintf("      entdata      %6i\n", bspMem->shared.all.entdatasize);
  49.  
  50.     if (bspMem->availHeaders & printType & LUMP_NODES)
  51.       mprintf("%5i nodes        %6i\n", bspMem->shared.all.numnodes, (int)(bspMem->shared.all.numnodes * (bspMem->bspVersion == BSP_VERSION_Q1 ? sizeof(struct dnode_t) : sizeof(struct dnode2_t))));
  52.  
  53.     if (bspMem->availHeaders & printType & LUMP_MODELS)
  54.       mprintf("%5i models       %6i\n", bspMem->shared.all.nummodels, (int)(bspMem->shared.all.nummodels * (bspMem->bspVersion == BSP_VERSION_Q1 ? sizeof(struct dmodel_t) : sizeof(struct dmodel2_t))));
  55.  
  56.     if (bspMem->availHeaders & printType & LUMP_TEXINFO)
  57.       mprintf("%5i texinfo      %6i\n", bspMem->shared.all.numtexinfo, (int)(bspMem->shared.all.numtexinfo * (bspMem->bspVersion == BSP_VERSION_Q1 ? sizeof(struct texinfo) : sizeof(struct texinfo2))));
  58.  
  59.     if (bspMem->availHeaders & printType & LUMP_LEAFS)
  60.       mprintf("%5i leafs        %6i\n", bspMem->shared.all.numleafs, (int)(bspMem->shared.all.numleafs * (bspMem->bspVersion == BSP_VERSION_Q1 ? sizeof(struct dleaf_t) : sizeof(struct dleaf2_t))));
  61.  
  62.     /*if(bspMem->bspVersion == BSP_VERSION_Q1) { */
  63.     if (bspMem->availHeaders & printType & LUMP_CLIPNODES)
  64.       mprintf("%5i clipnodes    %6i\n", bspMem->shared.quake1.numclipnodes, (int)(bspMem->shared.quake1.numclipnodes * sizeof(struct dclipnode_t)));
  65.  
  66.     if (bspMem->availHeaders & printType & LUMP_TEXTURES) {
  67.       if (!bspMem->shared.quake1.texdatasize)
  68.     mprintf("    0 textures          0\n");
  69.       else
  70.     mprintf("%5i textures     %6i\n", toDisk ? LittleLong(((struct dmiptexlump_t *)bspMem->shared.quake1.dtexdata)->nummiptex) : ((struct dmiptexlump_t *)bspMem->shared.quake1.dtexdata)->nummiptex, bspMem->shared.quake1.texdatasize);
  71.     }
  72.     /*} */
  73.     /*else if(bspMem->bspVersion == BSP_VERSION_Q2) { */
  74.     if (bspMem->availHeaders & printType & LUMP_AREAS)
  75.       mprintf("%5i areas        %6i\n", bspMem->shared.quake2.numareas, (int)(bspMem->shared.quake2.numareas * sizeof(struct darea2_t)));
  76.  
  77.     if (bspMem->availHeaders & printType & LUMP_AREAPORTALS)
  78.       mprintf("%5i areaportals  %6i\n", bspMem->shared.quake2.numareaportals, (int)(bspMem->shared.quake2.numareaportals * sizeof(struct dareaportal2_t)));
  79.  
  80.     if (bspMem->availHeaders & printType & LUMP_BRUSHES)
  81.       mprintf("%5i brushes      %6i\n", bspMem->shared.quake2.numbrushes, (int)(bspMem->shared.quake2.numbrushes * sizeof(struct dbrush2_t)));
  82.  
  83.     if (bspMem->availHeaders & printType & LUMP_BRUSHSIDES)
  84.       mprintf("%5i brushsides   %6i\n", bspMem->shared.quake2.numbrushsides, (int)(bspMem->shared.quake2.numbrushsides * sizeof(struct dbrushside2_t)));
  85.  
  86.     if (bspMem->availHeaders & printType & LUMP_LEAFBRUSHES)
  87.       mprintf("%5i leafbrushes  %6i\n", bspMem->shared.quake2.numleafbrushes, (int)(bspMem->shared.quake2.numleafbrushes * sizeof(unsigned short int)));
  88.  
  89.     /*} */
  90.  
  91.     if (bspMem->availHeaders & printType & MAP_ENTITIES)
  92.       mprintf("%5i entities     %6i\n", bspMem->nummapentities, (int)(bspMem->nummapentities * sizeof(struct entity)));
  93.  
  94.     if (bspMem->availHeaders & printType & MAP_TEXSTRINGS)
  95.       mprintf("%5i texstrings   %6i\n", bspMem->nummaptexstrings, (int)(bspMem->nummaptexstrings * (sizeof(char *) + 16)));
  96.  
  97.     if (bspMem->availHeaders & printType & MAP_BRUSHFACES)
  98.       mprintf("%5i brushfaces   %6i\n", bspMem->numbrushfaces, (int)(bspMem->numbrushfaces * sizeof(struct mface)));
  99.  
  100.     if (bspMem->availHeaders & printType & MAP_BRUSHPLANES)
  101.       mprintf("%5i brushplanes  %6i\n", bspMem->numbrushplanes, (int)(bspMem->numbrushplanes * sizeof(struct plane)));
  102.   }
  103. }
  104.  
  105. /*
  106.  * =============
  107.  * AllocBSP
  108.  * =============
  109.  */
  110. void AllocClusters(__memBase, int allocType)
  111. {
  112.   if (bspMem) {
  113.     if (!bspMem->bspVersion)
  114.       bspMem->bspVersion = BSP_VERSION_Q1;
  115.  
  116.     oprintf("allocmask: %lx\n", allocType);
  117.  
  118.     if (allocType & LUMP_ENTITIES) {
  119.       if (bspMem->shared.all.dentdata)
  120.     tfree(bspMem->shared.all.dentdata);
  121.       if (!(bspMem->shared.all.dentdata = tmalloc((bspMem->shared.all.max_entdatasize = CLUSTER_ENTSTRING) * sizeof(char))))
  122.       Error(failed_memoryunsize, "entities");
  123.  
  124.       bspMem->shared.all.entdatasize = 0;
  125.       oprintf("first cluster for entities allocated: %7d bytes (%lx)\n", CLUSTER_ENTSTRING * sizeof(char), bspMem->shared.all.dentdata);
  126.     }
  127.     if (allocType & LUMP_PLANES) {
  128.       if (bspMem->shared.all.dplanes)
  129.     tfree(bspMem->shared.all.dplanes);
  130.       if (!(bspMem->shared.all.dplanes = tmalloc((bspMem->shared.all.max_numplanes = CLUSTER_PLANES) * sizeof(struct dplane_t))))
  131.       Error(failed_memoryunsize, "planes");
  132.  
  133.       bspMem->shared.all.numplanes = 0;
  134.       oprintf("first cluster for planes allocated: %7d bytes (%lx)\n", CLUSTER_PLANES * sizeof(struct dplane_t), bspMem->shared.all.dplanes);
  135.     }
  136.     if (allocType & LUMP_VERTEXES) {
  137.       if (bspMem->shared.all.dvertexes)
  138.     tfree(bspMem->shared.all.dvertexes);
  139.       if (!(bspMem->shared.all.dvertexes = tmalloc((bspMem->shared.all.max_numvertexes = CLUSTER_VERTS) * sizeof(struct dvertex_t))))
  140.       Error(failed_memoryunsize, "vertexes");
  141.  
  142.       bspMem->shared.all.numvertexes = 0;
  143.       oprintf("first cluster for vertexes allocated: %7d bytes (%lx)\n", CLUSTER_VERTS * sizeof(struct dvertex_t), bspMem->shared.all.dvertexes);
  144.     }
  145.     if (allocType & LUMP_VISIBILITY) {
  146.       if (bspMem->shared.all.dvisdata)
  147.     tfree(bspMem->shared.all.dvisdata);
  148.       if (!(bspMem->shared.all.dvisdata = tmalloc((bspMem->shared.all.max_visdatasize = CLUSTER_VISIBILITY) * sizeof(char))))
  149.       Error(failed_memoryunsize, "visibility");
  150.  
  151.       bspMem->shared.all.visdatasize = 0;
  152.       oprintf("first cluster for visibility allocated: %7d bytes (%lx)\n", CLUSTER_VISIBILITY * sizeof(char), bspMem->shared.all.dvisdata);
  153.     }
  154.     if (allocType & LUMP_NODES) {
  155.       if (bspMem->shared.all.dnodes)
  156.     tfree(bspMem->shared.all.dnodes);
  157.       if (!(bspMem->shared.all.dnodes = tmalloc((bspMem->shared.all.max_numnodes = CLUSTER_NODES) * (bspMem->bspVersion == BSP_VERSION_Q1 ? sizeof(struct dnode_t) : sizeof(struct dnode2_t)))))
  158.       Error(failed_memoryunsize, "nodes");
  159.  
  160.       bspMem->shared.all.numnodes = 0;
  161.       oprintf("first cluster for nodes allocated: %7d bytes (%lx)\n", CLUSTER_NODES * (bspMem->bspVersion == BSP_VERSION_Q1 ? sizeof(struct dnode_t) : sizeof(struct dnode2_t)), bspMem->shared.all.dnodes);
  162.     }
  163.     if (allocType & LUMP_TEXINFO) {
  164.       if (bspMem->shared.all.texinfo)
  165.     tfree(bspMem->shared.all.texinfo);
  166.       if (!(bspMem->shared.all.texinfo = tmalloc((bspMem->shared.all.max_numtexinfo = CLUSTER_TEXINFO) * (bspMem->bspVersion == BSP_VERSION_Q1 ? sizeof(struct texinfo) : sizeof(struct texinfo2)))))
  167.       Error(failed_memoryunsize, "texinfo");
  168.  
  169.       bspMem->shared.all.numtexinfo = 0;
  170.       oprintf("first cluster for texinfo allocated: %7d bytes (%lx)\n", CLUSTER_TEXINFO * (bspMem->bspVersion == BSP_VERSION_Q1 ? sizeof(struct texinfo) : sizeof(struct texinfo2)), bspMem->shared.all.texinfo);
  171.     }
  172.     if (allocType & LUMP_FACES) {
  173.       if (bspMem->shared.all.dfaces)
  174.     tfree(bspMem->shared.all.dfaces);
  175.       if (!(bspMem->shared.all.dfaces = tmalloc((bspMem->shared.all.max_numfaces = CLUSTER_FACES) * sizeof(struct dface_t))))
  176.       Error(failed_memoryunsize, "faces");
  177.  
  178.       bspMem->shared.all.numfaces = 0;
  179.       oprintf("first cluster for faces allocated: %7d bytes (%lx)\n", CLUSTER_FACES * sizeof(struct dface_t), bspMem->shared.all.dfaces);
  180.     }
  181.     if (allocType & LUMP_LIGHTING) {
  182.       if (bspMem->shared.all.dlightdata)
  183.     tfree(bspMem->shared.all.dlightdata);
  184.       if (!(bspMem->shared.all.dlightdata = tmalloc((bspMem->shared.all.max_lightdatasize = CLUSTER_LIGHTING) * sizeof(char))))
  185.       Error(failed_memoryunsize, "lightdata");
  186.  
  187.       bspMem->shared.all.lightdatasize = 0;
  188.       oprintf("first cluster for lighting allocated: %7d bytes (%lx)\n", CLUSTER_LIGHTING * sizeof(char), bspMem->shared.all.dlightdata);
  189.     }
  190.     if (allocType & LUMP_LEAFS) {
  191.       if (bspMem->shared.all.dleafs)
  192.     tfree(bspMem->shared.all.dleafs);
  193.       if (!(bspMem->shared.all.dleafs = tmalloc((bspMem->shared.all.max_numleafs = CLUSTER_LEAFS) * (bspMem->bspVersion == BSP_VERSION_Q1 ? sizeof(struct dleaf_t) : sizeof(struct dleaf2_t)))))
  194.       Error(failed_memoryunsize, "leafs");
  195.  
  196.       bspMem->shared.all.numleafs = 0;
  197.       oprintf("first cluster for leafs allocated: %7d bytes (%lx)\n", CLUSTER_LEAFS * (bspMem->bspVersion == BSP_VERSION_Q1 ? sizeof(struct dleaf_t) : sizeof(struct dleaf2_t)), bspMem->shared.all.dleafs);
  198.     }
  199.     if (allocType & LUMP_MARKSURFACES) {
  200.       if (bspMem->shared.all.dmarksurfaces)
  201.     tfree(bspMem->shared.all.dmarksurfaces);
  202.       if (!(bspMem->shared.all.dmarksurfaces = tmalloc((bspMem->shared.all.max_nummarksurfaces = CLUSTER_MARKSURFACES) * sizeof(unsigned short int))))
  203.       Error(failed_memoryunsize, "marksurfaces");
  204.  
  205.       bspMem->shared.all.nummarksurfaces = 0;
  206.       oprintf("first cluster for marksurfaces allocated: %7d bytes (%lx)\n", CLUSTER_MARKSURFACES * sizeof(unsigned short int), bspMem->shared.all.dmarksurfaces);
  207.     }
  208.     if (allocType & LUMP_EDGES) {
  209.       if (bspMem->shared.all.dedges)
  210.     tfree(bspMem->shared.all.dedges);
  211.       if (bspMem->edgefaces[0])
  212.     tfree(bspMem->edgefaces[0]);
  213.       if (bspMem->edgefaces[1])
  214.     tfree(bspMem->edgefaces[1]);
  215.  
  216.       if (!(bspMem->shared.all.dedges = tmalloc((bspMem->shared.all.max_numedges = CLUSTER_EDGES) * sizeof(struct dedge_t))))
  217.       Error(failed_memoryunsize, "edges");
  218.       if (!(bspMem->edgefaces[0] = tmalloc(CLUSTER_EDGES * sizeof(struct visfacet **))))
  219.       Error(failed_memoryunsize, "edgefaces[0]");
  220.       if (!(bspMem->edgefaces[1] = tmalloc(CLUSTER_EDGES * sizeof(struct visfacet **))))
  221.       Error(failed_memoryunsize, "edgefaces[1]");
  222.  
  223.       bspMem->shared.all.numedges = 0;
  224.       oprintf("first cluster for edges allocated: %7d bytes (%lx)\n", CLUSTER_EDGES * sizeof(struct dedge_t), bspMem->shared.all.dedges);
  225.       oprintf("first cluster for edgefaces[0] allocated: %7d bytes (%lx)\n", CLUSTER_EDGES * sizeof(struct visfacet **), bspMem->edgefaces[0]);
  226.       oprintf("first cluster for edgefaces[1] allocated: %7d bytes (%lx)\n", CLUSTER_EDGES * sizeof(struct visfacet **), bspMem->edgefaces[1]);
  227.     }
  228.     if (allocType & LUMP_SURFEDGES) {
  229.       if (bspMem->shared.all.dsurfedges)
  230.     tfree(bspMem->shared.all.dsurfedges);
  231.       if (!(bspMem->shared.all.dsurfedges = tmalloc((bspMem->shared.all.max_numsurfedges = CLUSTER_SURFEDGES) * sizeof(int))))
  232.       Error(failed_memoryunsize, "surfedges");
  233.  
  234.       bspMem->shared.all.numsurfedges = 0;
  235.       oprintf("first cluster for surfedges allocated: %7d bytes (%lx)\n", CLUSTER_SURFEDGES * sizeof(int), bspMem->shared.all.dsurfedges);
  236.     }
  237.     if (allocType & LUMP_MODELS) {
  238.       if (bspMem->shared.all.dmodels)
  239.     tfree(bspMem->shared.all.dmodels);
  240.       if (!(bspMem->shared.all.dmodels = tmalloc((bspMem->shared.all.max_nummodels = CLUSTER_MODELS) * (bspMem->bspVersion == BSP_VERSION_Q1 ? sizeof(struct dmodel_t) : sizeof(struct dmodel2_t)))))
  241.       Error(failed_memoryunsize, "models");
  242.  
  243.       bspMem->shared.all.nummodels = 0;
  244.       oprintf("first cluster for models allocated: %7d bytes (%lx)\n", CLUSTER_MODELS * (bspMem->bspVersion == BSP_VERSION_Q1 ? sizeof(struct dmodel_t) : sizeof(struct dmodel2_t)), bspMem->shared.all.dmodels);
  245.     }
  246.  
  247.     /*if(bspMem->bspVersion == BSP_VERSION_Q1) { */
  248.     if (allocType & LUMP_TEXTURES) {
  249.       if (bspMem->shared.quake1.dtexdata)
  250.     tfree(bspMem->shared.quake1.dtexdata);
  251.       if (!(bspMem->shared.quake1.dtexdata = tmalloc((bspMem->shared.quake1.max_texdatasize = CLUSTER_TEXTURES) * sizeof(char))))
  252.       Error(failed_memoryunsize, "textures");
  253.  
  254.       bspMem->shared.quake1.texdatasize = 0;
  255.       oprintf("first cluster for textures allocated: %7d bytes (%lx)\n", CLUSTER_TEXTURES * sizeof(char), bspMem->shared.quake1.dtexdata);
  256.     }
  257.     if (allocType & LUMP_CLIPNODES) {
  258.       if (bspMem->shared.quake1.dclipnodes)
  259.     tfree(bspMem->shared.quake1.dclipnodes);
  260.       if (!(bspMem->shared.quake1.dclipnodes = tmalloc((bspMem->shared.quake1.max_numclipnodes = CLUSTER_CLIPNODES) * sizeof(struct dclipnode_t))))
  261.       Error(failed_memoryunsize, "clipnodes");
  262.  
  263.       bspMem->shared.quake1.numclipnodes = 0;
  264.       oprintf("first cluster for clipnodes allocated: %7d bytes (%lx)\n", CLUSTER_CLIPNODES * sizeof(struct dclipnode_t), bspMem->shared.quake1.dclipnodes);
  265.     }
  266.     /*} */
  267.     /*else if(bspMem->bspVersion == BSP_VERSION_Q2) { */
  268.     if (allocType & LUMP_AREAS) {
  269.       if (bspMem->shared.quake2.dareas)
  270.     tfree(bspMem->shared.quake2.dareas);
  271.       if (!(bspMem->shared.quake2.dareas = tmalloc((bspMem->shared.quake2.max_numareas = CLUSTER_AREAS) * sizeof(struct darea2_t))))
  272.       Error(failed_memoryunsize, "areas");
  273.  
  274.       bspMem->shared.quake2.numareas = 0;
  275.       oprintf("first cluster for areas allocated: %7d bytes (%lx)\n", CLUSTER_AREAS * sizeof(struct darea2_t), bspMem->shared.quake2.dareas);
  276.     }
  277.     if (allocType & LUMP_AREAPORTALS) {
  278.       if (bspMem->shared.quake2.dareaportals)
  279.     tfree(bspMem->shared.quake2.dareaportals);
  280.       if (!(bspMem->shared.quake2.dareaportals = tmalloc((bspMem->shared.quake2.max_numareaportals = CLUSTER_AREAPORTALS) * sizeof(struct dareaportal2_t))))
  281.       Error(failed_memoryunsize, "areaportals");
  282.  
  283.       bspMem->shared.quake2.numareaportals = 0;
  284.       oprintf("first cluster for areaportals allocated: %7d bytes (%lx)\n", CLUSTER_AREAPORTALS * sizeof(struct dareaportal2_t), bspMem->shared.quake2.dareaportals);
  285.     }
  286.     if (allocType & LUMP_BRUSHES) {
  287.       if (bspMem->shared.quake2.dbrushes)
  288.     tfree(bspMem->shared.quake2.dbrushes);
  289.       if (!(bspMem->shared.quake2.dbrushes = tmalloc((bspMem->shared.quake2.max_numbrushes = CLUSTER_BRUSHES) * sizeof(struct dbrush2_t))))
  290.       Error(failed_memoryunsize, "brushes");
  291.  
  292.       bspMem->shared.quake2.numbrushes = 0;
  293.       oprintf("first cluster for brushes allocated: %7d bytes (%lx)\n", CLUSTER_BRUSHES * sizeof(struct dbrush2_t), bspMem->shared.quake2.dbrushes);
  294.     }
  295.     if (allocType & LUMP_BRUSHSIDES) {
  296.       if (bspMem->shared.quake2.dbrushsides)
  297.     tfree(bspMem->shared.quake2.dbrushsides);
  298.       if (!(bspMem->shared.quake2.dbrushsides = tmalloc((bspMem->shared.quake2.max_numbrushsides = CLUSTER_BRUSHSIDES) * sizeof(struct dbrushside2_t))))
  299.       Error(failed_memoryunsize, "brushsides");
  300.  
  301.       bspMem->shared.quake2.numbrushsides = 0;
  302.       oprintf("first cluster for brushsides allocated: %7d bytes (%lx)\n", CLUSTER_BRUSHSIDES * sizeof(struct dbrushside2_t), bspMem->shared.quake2.dbrushsides);
  303.     }
  304.     if (allocType & LUMP_LEAFBRUSHES) {
  305.       if (bspMem->shared.quake2.dleafbrushes)
  306.     tfree(bspMem->shared.quake2.dleafbrushes);
  307.       if (!(bspMem->shared.quake2.dleafbrushes = tmalloc((bspMem->shared.quake2.max_numleafbrushes = CLUSTER_LEAFBRUSHES) * sizeof(unsigned short int))))
  308.       Error(failed_memoryunsize, "leafbrushes");
  309.  
  310.       bspMem->shared.quake2.numleafbrushes = 0;
  311.       oprintf("first cluster for leafbrushes allocated: %7d bytes (%lx)\n", CLUSTER_LEAFBRUSHES * sizeof(unsigned short int), bspMem->shared.quake2.dleafbrushes);
  312.     }
  313.     /*} */
  314.  
  315.     if (allocType & MAP_ENTITIES) {
  316.       if (bspMem->mapentities)
  317.     tfree(bspMem->mapentities);
  318.       if (!(bspMem->mapentities = tmalloc((bspMem->max_nummapentities = CLUSTER_ENTITIES) * sizeof(struct entity))))
  319.       Error(failed_memoryunsize, "entities");
  320.  
  321.       bspMem->nummapentities = 0;
  322.       oprintf("first cluster for brushes allocated: %7d bytes (%lx)\n", CLUSTER_ENTITIES * sizeof(struct entity), bspMem->mapentities);
  323.     }
  324.     if (allocType & MAP_TEXSTRINGS) {
  325.       int i;
  326.       char *text;
  327.  
  328.       if (bspMem->maptexstrings)
  329.     tfree(bspMem->maptexstrings);
  330.       if (!(bspMem->maptexstrings = tmalloc((bspMem->max_nummaptexstrings = CLUSTER_TEXSTRINGS) * (sizeof(char *) + 16))))
  331.       Error(failed_memoryunsize, "texstrings");
  332.  
  333.       bspMem->nummaptexstrings = 0;
  334.       for (i = 0, text = (char *)&bspMem->maptexstrings[bspMem->max_nummaptexstrings]; i < bspMem->max_nummaptexstrings; i++, text += 16)
  335.     bspMem->maptexstrings[i] = text;
  336.       oprintf("first cluster for texstrings allocated: %7d bytes (%lx)\n", CLUSTER_TEXSTRINGS * (sizeof(char *) + 16), bspMem->maptexstrings);
  337.     }
  338.     if (allocType & MAP_BRUSHFACES) {
  339.       if (bspMem->brushfaces)
  340.     tfree(bspMem->brushfaces);
  341.       if (!(bspMem->brushfaces = tmalloc((bspMem->max_numbrushfaces = CLUSTER_BRUSHFACES) * sizeof(struct mface))))
  342.       Error(failed_memoryunsize, "brushfaces");
  343.  
  344.       bspMem->numbrushfaces = 0;
  345.       oprintf("first cluster for brushfaces allocated: %7d bytes (%lx)\n", CLUSTER_BRUSHFACES * sizeof(struct mface), bspMem->brushfaces);
  346.     }
  347.     if (allocType & MAP_BRUSHPLANES) {
  348.       if (bspMem->brushplanes)
  349.     tfree(bspMem->brushplanes);
  350.       if (!(bspMem->brushplanes = tmalloc((bspMem->max_numbrushplanes = CLUSTER_BRUSHPLANES) * sizeof(struct plane))))
  351.       Error(failed_memoryunsize, "brushplanes");
  352.  
  353.       bspMem->numbrushplanes = 0;
  354.       oprintf("first cluster for brushes allocated: %7d bytes (%lx)\n", CLUSTER_BRUSHPLANES * sizeof(struct plane), bspMem->brushplanes);
  355.     }
  356.     bspMem->availHeaders |= allocType;
  357.  
  358. #ifdef    CUSTOM_MAXIMA
  359.     if (!bspMem->maxpoints)
  360.       bspMem->maxpoints = DEFPOINTS;
  361.     if (!bspMem->maxedges)
  362.       bspMem->maxedges = DEFEDGES;
  363.     if (!bspMem->maxedges_in_region)
  364.       bspMem->maxedges_in_region = DEF_EDGES_IN_REGION;
  365.     if (!bspMem->maxportals)
  366.       bspMem->maxportals = DEF_PORTALS;
  367.     if (!bspMem->maxportals_in_leaf)
  368.       bspMem->maxportals_in_leaf = DEF_PORTALS_IN_LEAF;
  369. #endif
  370.   }
  371. }
  372.  
  373. /*
  374.  * =============
  375.  * ExpandBSP
  376.  * =============
  377.  * for all use trealloc instead ?
  378.  */
  379. void ExpandClusters(__memBase, int allocType)
  380. {
  381.   if (bspMem) {
  382.     if (!bspMem->bspVersion)
  383.       bspMem->bspVersion = BSP_VERSION_Q1;
  384.     oprintf("expandmask: %lx\n", allocType);
  385.  
  386.     if (allocType & LUMP_ENTITIES) {
  387.       if (!(bspMem->shared.all.dentdata = trealloc(bspMem->shared.all.dentdata, (bspMem->shared.all.max_entdatasize += CLUSTER_ENTSTRING) * sizeof(char))))
  388.       Error(failed_memoryunsize, "entities");
  389.       oprintf("additional cluster for entities allocated: %7d bytes (%lx)\n", bspMem->shared.all.max_entdatasize * sizeof(char), bspMem->shared.all.dentdata);
  390.     }
  391.     if (allocType & LUMP_PLANES) {
  392.       if (!(bspMem->shared.all.dplanes = trealloc(bspMem->shared.all.dplanes, (bspMem->shared.all.max_numplanes += CLUSTER_PLANES) * sizeof(struct dplane_t))))
  393.       Error(failed_memoryunsize, "planes");
  394.       oprintf("additional cluster for planes allocated: %7d bytes (%lx)\n", bspMem->shared.all.max_numplanes * sizeof(struct dplane_t), bspMem->shared.all.dplanes);
  395.     }
  396.     if (allocType & LUMP_VERTEXES) {
  397.       if (!(bspMem->shared.all.dvertexes = trealloc(bspMem->shared.all.dvertexes, (bspMem->shared.all.max_numvertexes += CLUSTER_VERTS) * sizeof(struct dvertex_t))))
  398.       Error(failed_memoryunsize, "vertexes");
  399.       oprintf("additional cluster for vertexes allocated: %7d bytes (%lx)\n", bspMem->shared.all.max_numvertexes * sizeof(struct dvertex_t), bspMem->shared.all.dvertexes);
  400.     }
  401.     if (allocType & LUMP_VISIBILITY) {
  402.       if (!(bspMem->shared.all.dvisdata = trealloc(bspMem->shared.all.dvisdata, (bspMem->shared.all.max_visdatasize += CLUSTER_VISIBILITY) * sizeof(char))))
  403.       Error(failed_memoryunsize, "visibility");
  404.       oprintf("additional cluster for visibility allocated: %7d bytes (%lx)\n", bspMem->shared.all.max_visdatasize * sizeof(char), bspMem->shared.all.dvisdata);
  405.     }
  406.     if (allocType & LUMP_NODES) {
  407.       if ((bspMem->shared.all.dnodes = trealloc(bspMem->shared.all.dnodes, (bspMem->shared.all.max_numnodes += CLUSTER_NODES) * (bspMem->bspVersion == BSP_VERSION_Q1 ? sizeof(struct dnode_t) : sizeof(struct dnode2_t)))))
  408.       Error(failed_memoryunsize, "nodes");
  409.       oprintf("additional cluster for nodes allocated: %7d bytes (%lx)\n", bspMem->shared.all.max_numnodes * (bspMem->bspVersion == BSP_VERSION_Q1 ? sizeof(struct dnode_t) : sizeof(struct dnode2_t)), bspMem->shared.all.dnodes);
  410.     }
  411.     if (allocType & LUMP_TEXINFO) {
  412.       if (!(bspMem->shared.all.texinfo = trealloc(bspMem->shared.all.texinfo, (bspMem->shared.all.max_numtexinfo += CLUSTER_TEXINFO) * (bspMem->bspVersion == BSP_VERSION_Q1 ? sizeof(struct texinfo) : sizeof(struct texinfo2)))))
  413.       Error(failed_memoryunsize, "texinfo");
  414.       oprintf("additional cluster for texinfo allocated: %7d bytes (%lx)\n", bspMem->shared.all.max_numtexinfo * (bspMem->bspVersion == BSP_VERSION_Q1 ? sizeof(struct texinfo) : sizeof(struct texinfo2)), bspMem->shared.all.texinfo);
  415.     }
  416.     if (allocType & LUMP_FACES) {
  417.       if (!(bspMem->shared.all.dfaces = trealloc(bspMem->shared.all.dfaces, (bspMem->shared.all.max_numfaces += CLUSTER_FACES) * sizeof(struct dface_t))))
  418.       Error(failed_memoryunsize, "faces");
  419.       oprintf("additional cluster for faces allocated: %7d bytes (%lx)\n", bspMem->shared.all.max_numfaces * sizeof(struct dface_t), bspMem->shared.all.dfaces);
  420.     }
  421.     if (allocType & LUMP_LIGHTING) {
  422.       if (!(bspMem->shared.all.dlightdata = trealloc(bspMem->shared.all.dlightdata, (bspMem->shared.all.max_lightdatasize += CLUSTER_LIGHTING) * sizeof(char))))
  423.       Error(failed_memoryunsize, "lightdata");
  424.       oprintf("additional cluster for lighting allocated: %7d bytes (%lx)\n", bspMem->shared.all.max_lightdatasize * sizeof(char), bspMem->shared.all.dlightdata);
  425.     }
  426.     if (allocType & LUMP_LEAFS) {
  427.       if (!(bspMem->shared.all.dleafs = trealloc(bspMem->shared.all.dleafs, (bspMem->shared.all.max_numleafs += CLUSTER_LEAFS) * (bspMem->bspVersion == BSP_VERSION_Q1 ? sizeof(struct dleaf_t) : sizeof(struct dleaf2_t)))))
  428.       Error(failed_memoryunsize, "leafs");
  429.       oprintf("additional cluster for leafs allocated: %7d bytes (%lx)\n", bspMem->shared.all.max_numleafs * (bspMem->bspVersion == BSP_VERSION_Q1 ? sizeof(struct dleaf_t) : sizeof(struct dleaf2_t)), bspMem->shared.all.dleafs);
  430.     }
  431.     if (allocType & LUMP_MARKSURFACES) {
  432.       if (!(bspMem->shared.all.dmarksurfaces = trealloc(bspMem->shared.all.dmarksurfaces, (bspMem->shared.all.max_nummarksurfaces += CLUSTER_MARKSURFACES) * sizeof(unsigned short int))))
  433.       Error(failed_memoryunsize, "marksurfaces");
  434.       oprintf("additional cluster for marksurfaces allocated: %7d bytes (%lx)\n", bspMem->shared.all.max_nummarksurfaces * sizeof(unsigned short int), bspMem->shared.all.dmarksurfaces);
  435.     }
  436.     if (allocType & LUMP_EDGES) {
  437.       if (!(bspMem->shared.all.dedges = trealloc(bspMem->shared.all.dedges, (bspMem->shared.all.max_numedges += CLUSTER_EDGES) * sizeof(struct dedge_t))))
  438.       Error(failed_memoryunsize, "edges");
  439.       if (!(bspMem->edgefaces[0] = trealloc(bspMem->edgefaces[0], bspMem->shared.all.max_numedges * sizeof(struct visfacet **))))
  440.       Error(failed_memoryunsize, "edgefaces[0]");
  441.       if (!(bspMem->edgefaces[1] = trealloc(bspMem->edgefaces[1], bspMem->shared.all.max_numedges * sizeof(struct visfacet **))))
  442.       Error(failed_memoryunsize, "edgefaces[1]");
  443.       oprintf("additional cluster for edges allocated: %7d bytes (%lx)\n", bspMem->shared.all.max_numedges * sizeof(struct dedge_t), bspMem->shared.all.dedges);
  444.       oprintf("additional cluster for edgefaces[0] allocated: %7d bytes (%lx)\n", bspMem->shared.all.max_numedges * sizeof(struct visfacet **), bspMem->edgefaces[0]);
  445.       oprintf("additional cluster for edgefaces[1] allocated: %7d bytes (%lx)\n", bspMem->shared.all.max_numedges * sizeof(struct visfacet **), bspMem->edgefaces[1]);
  446.     }
  447.     if (allocType & LUMP_SURFEDGES) {
  448.       if (!(bspMem->shared.all.dsurfedges = trealloc(bspMem->shared.all.dsurfedges, (bspMem->shared.all.max_numsurfedges += CLUSTER_SURFEDGES) * sizeof(int))))
  449.       Error(failed_memoryunsize, "surfedges");
  450.       oprintf("additional cluster for surfedges allocated: %7d bytes (%lx)\n", bspMem->shared.all.max_numsurfedges * sizeof(int), bspMem->shared.all.dsurfedges);
  451.     }
  452.     if (allocType & LUMP_MODELS) {
  453.       if (!(bspMem->shared.all.dmodels = trealloc(bspMem->shared.all.dmodels, (bspMem->shared.all.max_nummodels += CLUSTER_MODELS) * (bspMem->bspVersion == BSP_VERSION_Q1 ? sizeof(struct dmodel_t) : sizeof(struct dmodel2_t)))))
  454.       Error(failed_memoryunsize, "models");
  455.       oprintf("additional cluster for models allocated: %7d bytes (%lx)\n", bspMem->shared.all.max_nummodels * (bspMem->bspVersion == BSP_VERSION_Q1 ? sizeof(struct dmodel_t) : sizeof(struct dmodel2_t)), bspMem->shared.all.dmodels);
  456.     }
  457.  
  458.     /*if(bspMem->bspVersion == BSP_VERSION_Q1) { */
  459.     if (allocType & LUMP_TEXTURES) {
  460.       if (!(bspMem->shared.quake1.dtexdata = trealloc(bspMem->shared.quake1.dtexdata, (bspMem->shared.quake1.max_texdatasize += CLUSTER_TEXTURES) * sizeof(char))))
  461.       Error(failed_memoryunsize, "textures");
  462.       oprintf("additional cluster for textures allocated: %7d bytes (%lx)\n", bspMem->shared.quake1.max_texdatasize * sizeof(char), bspMem->shared.quake1.dtexdata);
  463.     }
  464.     if (allocType & LUMP_CLIPNODES) {
  465.       if (!(bspMem->shared.quake1.dclipnodes = trealloc(bspMem->shared.quake1.dclipnodes, (bspMem->shared.quake1.max_numclipnodes += CLUSTER_CLIPNODES) * sizeof(struct dclipnode_t))))
  466.       Error(failed_memoryunsize, "clipnodes");
  467.       oprintf("additional cluster for clipnodes allocated: %7d bytes (%lx)\n", bspMem->shared.quake1.max_numclipnodes * sizeof(struct dclipnode_t), bspMem->shared.quake1.dclipnodes);
  468.     }
  469.     /*} */
  470.     /*else if(bspMem->bspVersion == BSP_VERSION_Q2) { */
  471.     if (allocType & LUMP_AREAS) {
  472.       if (!(bspMem->shared.quake2.dareas = trealloc(bspMem->shared.quake2.dareas, (bspMem->shared.quake2.max_numareas += CLUSTER_AREAS) * sizeof(struct darea2_t))))
  473.       Error(failed_memoryunsize, "areas");
  474.       oprintf("additional cluster for areas allocated: %7d bytes (%lx)\n", bspMem->shared.quake2.max_numareas * sizeof(struct darea2_t), bspMem->shared.quake2.dareas);
  475.     }
  476.     if (allocType & LUMP_AREAPORTALS) {
  477.       if (!(bspMem->shared.quake2.dareaportals = trealloc(bspMem->shared.quake2.dareaportals, (bspMem->shared.quake2.max_numareaportals += CLUSTER_AREAPORTALS) * sizeof(struct dareaportal2_t))))
  478.       Error(failed_memoryunsize, "areaportals");
  479.       oprintf("additional cluster for areaportals allocated: %7d bytes (%lx)\n", bspMem->shared.quake2.max_numareaportals * sizeof(struct dareaportal2_t), bspMem->shared.quake2.dareaportals);
  480.     }
  481.     if (allocType & LUMP_BRUSHES) {
  482.       if (!(bspMem->shared.quake2.dbrushes = trealloc(bspMem->shared.quake2.dbrushes, (bspMem->shared.quake2.max_numbrushes += CLUSTER_BRUSHES) * sizeof(struct dbrush2_t))))
  483.       Error(failed_memoryunsize, "brushes");
  484.       oprintf("additional cluster for brushes allocated: %7d bytes (%lx)\n", bspMem->shared.quake2.max_numbrushes * sizeof(struct dbrush2_t), bspMem->shared.quake2.dbrushes);
  485.     }
  486.     if (allocType & LUMP_BRUSHSIDES) {
  487.       if (!(bspMem->shared.quake2.dbrushsides = trealloc(bspMem->shared.quake2.dbrushsides, (bspMem->shared.quake2.max_numbrushsides += CLUSTER_BRUSHSIDES) * sizeof(struct dbrushside2_t))))
  488.       Error(failed_memoryunsize, "brushsides");
  489.       oprintf("additional cluster for brushsides allocated: %7d bytes (%lx)\n", bspMem->shared.quake2.max_numbrushsides * sizeof(struct dbrushside2_t), bspMem->shared.quake2.dbrushsides);
  490.     }
  491.     if (allocType & LUMP_LEAFBRUSHES) {
  492.       if (!(bspMem->shared.quake2.dleafbrushes = trealloc(bspMem->shared.quake2.dleafbrushes, (bspMem->shared.quake2.max_numleafbrushes += CLUSTER_LEAFBRUSHES) * sizeof(unsigned short int))))
  493.       Error(failed_memoryunsize, "leafbrushes");
  494.       oprintf("additional cluster for leafbrushes allocated: %7d bytes (%lx)\n", bspMem->shared.quake2.max_numleafbrushes * sizeof(unsigned short int), bspMem->shared.quake2.dleafbrushes);
  495.     }
  496.     /*} */
  497.  
  498.     if (allocType & MAP_ENTITIES) {
  499.       if (!(bspMem->mapentities = trealloc(bspMem->mapentities, (bspMem->max_nummapentities += CLUSTER_ENTITIES) * sizeof(struct entity))))
  500.       Error(failed_memoryunsize, "entities");
  501.       oprintf("additional cluster for mapentities allocated: %7d bytes (%lx)\n", bspMem->max_nummapentities * sizeof(struct entity), bspMem->mapentities);
  502.     }
  503.     if (allocType & MAP_TEXSTRINGS) {
  504.       int i;
  505.       char *text;
  506.       char **maptexstrings = bspMem->maptexstrings;
  507.       if (!(bspMem->maptexstrings = tmalloc((bspMem->max_nummaptexstrings += CLUSTER_TEXSTRINGS) * (sizeof(char *) + 16))))
  508.       Error(failed_memoryunsize, "texstrings");
  509.  
  510.       for (i = 0, text = (char *)&bspMem->maptexstrings[bspMem->max_nummaptexstrings]; i < bspMem->max_nummaptexstrings; i++, text += 16)
  511.     bspMem->maptexstrings[i] = text;
  512.       __memcpy(bspMem->maptexstrings[0], maptexstrings[0], bspMem->nummaptexstrings * 16);
  513.       tfree(maptexstrings);
  514.       oprintf("additional cluster for mapstrings allocated: %7d bytes (%lx)\n", bspMem->max_nummaptexstrings * (sizeof(char *) + 16), bspMem->maptexstrings);
  515.     }
  516.     if (allocType & MAP_BRUSHFACES) {
  517.       if (!(bspMem->brushfaces = trealloc(bspMem->brushfaces, (bspMem->max_numbrushplanes += CLUSTER_BRUSHFACES) * sizeof(struct mface))))
  518.       Error(failed_memoryunsize, "brushfaces");
  519.       oprintf("additional cluster for brushplanes allocated: %7d bytes (%lx)\n", bspMem->max_numbrushplanes * sizeof(struct mface), bspMem->brushfaces);
  520.     }
  521.     if (allocType & MAP_BRUSHPLANES) {
  522.       if (!(bspMem->brushplanes = trealloc(bspMem->brushplanes, (bspMem->max_numbrushplanes += CLUSTER_BRUSHPLANES) * sizeof(struct plane))))
  523.       Error(failed_memoryunsize, "brushplanes");
  524.       oprintf("additional cluster for brushplanes allocated: %7d bytes (%lx)\n", bspMem->max_numbrushplanes * sizeof(struct plane), bspMem->brushplanes);
  525.     }
  526.     bspMem->availHeaders |= allocType;
  527.  
  528. #ifdef    CUSTOM_MAXIMA
  529.     if (!bspMem->maxpoints)
  530.       bspMem->maxpoints = DEFPOINTS;
  531.     if (!bspMem->maxedges)
  532.       bspMem->maxedges = DEFEDGES;
  533.     if (!bspMem->maxedges_in_region)
  534.       bspMem->maxedges_in_region = DEF_EDGES_IN_REGION;
  535.     if (!bspMem->maxportals)
  536.       bspMem->maxportals = DEF_PORTALS;
  537.     if (!bspMem->maxportals_in_leaf)
  538.       bspMem->maxportals_in_leaf = DEF_PORTALS_IN_LEAF;
  539. #endif
  540.   }
  541. }
  542.  
  543. /*
  544.  * =============
  545.  * FreeBSP
  546.  * =============
  547.  */
  548. void FreeClusters(__memBase, int freeType)
  549. {
  550.   if (bspMem) {
  551.     if (!bspMem->bspVersion)
  552.       bspMem->bspVersion = BSP_VERSION_Q1;
  553.     if (!freeType)
  554.       freeType = bspMem->availHeaders;
  555.  
  556.     oprintf("freemask: %lx\n", freeType);
  557.  
  558.     if ((bspMem->availHeaders & freeType & LUMP_ENTITIES)) {
  559.       oprintf("free entities\n");
  560.       tfree(bspMem->shared.all.dentdata);
  561.     }
  562.     if ((bspMem->availHeaders & freeType & LUMP_PLANES)) {
  563.       oprintf("free planes\n");
  564.       tfree(bspMem->shared.all.dplanes);
  565.     }
  566.     if ((bspMem->availHeaders & freeType & LUMP_VERTEXES)) {
  567.       oprintf("free vertexes\n");
  568.       tfree(bspMem->shared.all.dvertexes);
  569.     }
  570.     if ((bspMem->availHeaders & freeType & LUMP_VISIBILITY)) {
  571.       oprintf("free visibility\n");
  572.       tfree(bspMem->shared.all.dvisdata);
  573.     }
  574.     if ((bspMem->availHeaders & freeType & LUMP_NODES)) {
  575.       oprintf("free nodes\n");
  576.       tfree(bspMem->shared.all.dnodes);
  577.     }
  578.     if ((bspMem->availHeaders & freeType & LUMP_TEXINFO)) {
  579.       oprintf("free texinfo\n");
  580.       tfree(bspMem->shared.all.texinfo);
  581.     }
  582.     if ((bspMem->availHeaders & freeType & LUMP_FACES)) {
  583.       oprintf("free faces\n");
  584.       tfree(bspMem->shared.all.dfaces);
  585.     }
  586.     if ((bspMem->availHeaders & freeType & LUMP_LIGHTING)) {
  587.       oprintf("free lighting\n");
  588.       tfree(bspMem->shared.all.dlightdata);
  589.     }
  590.     if ((bspMem->availHeaders & freeType & LUMP_LEAFS)) {
  591.       oprintf("free leafs\n");
  592.       tfree(bspMem->shared.all.dleafs);
  593.     }
  594.     if ((bspMem->availHeaders & freeType & LUMP_MARKSURFACES)) {
  595.       oprintf("free marksurfaces\n");
  596.       tfree(bspMem->shared.all.dmarksurfaces);
  597.     }
  598.     if ((bspMem->availHeaders & freeType & LUMP_EDGES)) {
  599.       oprintf("free edges\n");
  600.       tfree(bspMem->shared.all.dedges);
  601.       if (bspMem->edgefaces[0])
  602.     tfree(bspMem->edgefaces[0]);
  603.       if (bspMem->edgefaces[1])
  604.     tfree(bspMem->edgefaces[1]);
  605.     }
  606.     if ((bspMem->availHeaders & freeType & LUMP_SURFEDGES)) {
  607.       oprintf("free surfedges\n");
  608.       tfree(bspMem->shared.all.dsurfedges);
  609.     }
  610.     if ((bspMem->availHeaders & freeType & LUMP_MODELS)) {
  611.       oprintf("free models\n");
  612.       tfree(bspMem->shared.all.dmodels);
  613.     }
  614.  
  615.     /*if(bspMem->bspVersion == BSP_VERSION_Q1) { */
  616.     if ((bspMem->availHeaders & freeType & LUMP_TEXTURES)) {
  617.       oprintf("free textures\n");
  618.       tfree(bspMem->shared.quake1.dtexdata);
  619.     }
  620.     if ((bspMem->availHeaders & freeType & LUMP_CLIPNODES)) {
  621.       oprintf("free clipnodes\n");
  622.       tfree(bspMem->shared.quake1.dclipnodes);
  623.     }
  624.     /*} */
  625.     /*else if(bspMem->bspVersion == BSP_VERSION_Q2) { */
  626.     if ((bspMem->availHeaders & freeType & LUMP_AREAS)) {
  627.       oprintf("free areas\n");
  628.       tfree(bspMem->shared.quake2.dareas);
  629.     }
  630.     if ((bspMem->availHeaders & freeType & LUMP_AREAPORTALS)) {
  631.       oprintf("free areaportals\n");
  632.       tfree(bspMem->shared.quake2.dareaportals);
  633.     }
  634.     if ((bspMem->availHeaders & freeType & LUMP_BRUSHES)) {
  635.       oprintf("free brushes\n");
  636.       tfree(bspMem->shared.quake2.dbrushes);
  637.     }
  638.     if ((bspMem->availHeaders & freeType & LUMP_BRUSHSIDES)) {
  639.       oprintf("free brushsides\n");
  640.       tfree(bspMem->shared.quake2.dbrushsides);
  641.     }
  642.     if ((bspMem->availHeaders & freeType & LUMP_LEAFBRUSHES)) {
  643.       oprintf("free leafbrushes\n");
  644.       tfree(bspMem->shared.quake2.dleafbrushes);
  645.     }
  646.     /*} */
  647.  
  648.     if ((bspMem->availHeaders & freeType & MAP_ENTITIES)) {
  649.       struct entity *ent;
  650.       int i;
  651.  
  652.       oprintf("free entities\n");
  653.       for (i = 0, ent = bspMem->mapentities; i < bspMem->nummapentities; i++, ent++) {
  654.     struct epair *ep = ent->epairs;
  655.     struct mbrush *mbr = ent->brushes;
  656.  
  657.     while (ep) {
  658.       struct epair *en = ep->next;
  659.  
  660.       tfree(ep->key);
  661.       tfree(ep->value);
  662.       tfree(ep);
  663.       ep = en;
  664.     }
  665.     while (mbr) {
  666.       struct mbrush *mbn = mbr->next;
  667.       struct mface *mfc = mbr->faces;
  668.  
  669.       while (mfc) {
  670.         struct mface *mfn = mfc->next;
  671.  
  672.         tfree(mfc);
  673.         mfc = mfn;
  674.       }
  675.       tfree(mbr);
  676.       mbr = mbn;
  677.     }
  678.       }
  679.       tfree(bspMem->mapentities);
  680.     }
  681.     if ((bspMem->availHeaders & freeType & MAP_TEXSTRINGS)) {
  682.       oprintf("free texstrings\n");
  683.       tfree(bspMem->maptexstrings);
  684.     }
  685.     if ((bspMem->availHeaders & freeType & MAP_BRUSHFACES)) {
  686.       oprintf("free brushfaces\n");
  687.       tfree(bspMem->brushfaces);
  688.     }
  689.     if ((bspMem->availHeaders & freeType & MAP_BRUSHPLANES)) {
  690.       oprintf("free brushmaps\n");
  691.       tfree(bspMem->brushplanes);
  692.     }
  693.  
  694.     /*
  695.      * probably this is not ours;
  696.      * tfree(bspMem);
  697.      */
  698.   }
  699.   bspMem->availHeaders &= ~freeType;
  700. }
  701.